let Fly = require('flyio');
import { Spin } from 'ant-design-vue';
import Vue from 'vue';
let getChildrenTextContent = function (children) {
		return children
			.map(function (node) {
				return node.children ? getChildrenTextContent(node.children) : node.text;
			})
			.join('');
	},
	loadingStyle = {
		transition: '.4s',
		background: '#e8e8e8'
	},
	loadingNode;
Fly.config.timeout = 5000;
Fly.interceptors.request.use((config, promise) => {
	//给所有请求添加自定义header
	config.headers['token'] = '2e76aab1e837de194941341b80aa9061';
	// config.headers["X-Wechat-Token"]="mGQtpdhxnhW8ycPAAFjTu4kgq2nBZPnbfYz5TLXWkXGFAhB3nUgD0N6I80VMSNUG3RDD7LPl_v1V927SwFpK2E6NBQTbs7CDjTPtT8elYUO4mxFG2h51LNA5q4wqjiPOFKbxqyHeqkOtmw1eCM8KUI0p6Ia5lEUKwRP4jvjG7qOEThLNp0CKC8MzG9I3oUIjv3d862iQsPUxjU4ssoy9g9eJMYG1bqQ3lcPorhOPU_X3f4XPm1dyGWQy2meuiNtEMY1OLLKMvYMrZd0fHzF";
	//可以通过promise.reject／resolve直接中止请求
	//promise.resolve("fake data")
	loadingNode = new Vue({
		el: '#loading',
		data: {
			show: true
		},
		render: function (createElement) {
			if (this.show) {
				return createElement(
					'div',
					{
						class: {
							loadingClass: true
						}
					},
					['loainding...']
				);
			} else {
			}
		}
	});
	return config;
});
Fly.interceptors.response.use(
	(response) => {
		//只将请求结果的data字段返回
		loadingNode.show = false;
		return response.data;
	},
	(err) => {
		//发生网络错误后会走到这里
		//return Promise.resolve("ssss")
	}
);
export default Fly;
